from typing import List
from sqlalchemy import select

from db.db import AsyncSession
from models.models import FileForecast, Forecast
from schemas.schemas import ForecastSchema


async def get_all_forecast_name(session: AsyncSession):
    """Возвращает все названия прогноза."""
    query_result = await session.execute(select(FileForecast))
    return query_result.scalars().all()


async def get_forecast_by_id(
    forecast_id: int, session: AsyncSession
) -> List[ForecastSchema]:
    """Возвращает прогноз по ID."""
    query = select(Forecast).where(Forecast.id_filename == forecast_id)
    query_result = await session.execute(query)
    result = query_result.scalars().all()
    return [ForecastSchema(**forecast.__dict__).dict() for forecast in result]
